package com.alibaba.easyexcel.test.demo.web;

import com.alibaba.excel.event.WriteHandler;
import org.apache.poi.ss.usermodel.*;

/**
 * @author zhanbo
 * @version 1.0
 * @describe
 * @date 2020/8/11-15:14
 */
public class DefaultExcelStyle implements WriteHandler {

    private CellStyle cellStyle;

    @Override
    public void sheet(int sheetNo, Sheet sheet) {
        // 标题字体、高度、背景色
        Workbook workbook = sheet.getWorkbook();
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 10);
        cellStyle = workbook.createCellStyle();
        cellStyle.setFont(font);
        cellStyle.setFillBackgroundColor(IndexedColors.WHITE.getIndex());
    }

    @Override
    public void row(int rowNum, Row row) {

    }

    @Override
    public void cell(int cellNum, Cell cell) {
        // 设置标题样式
        if (cell.getRowIndex() == 0) {
            cell.setCellStyle(cellStyle);
        }
    }
}
